# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=libspectre
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.2.8
pkgrel=2
arch=('any')
pkgdesc="libspectre is a small library for rendering PostScript documents. It provides a convenient easy to use API for handling and rendering PostScript documents (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-ghostscript"
         "${MINGW_PACKAGE_PREFIX}-cairo")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-libidn"
            "${MINGW_PACKAGE_PREFIX}-pkg-config"
            "libtool"
            "automake-wrapper"
            "autoconf"
            "make")
options=('strip' 'staticlibs')
license=("GPL 2")
url="https://www.freedesktop.org/wiki/Software/libspectre/"
source=(https://libspectre.freedesktop.org/releases/${_realname}-${pkgver}.tar.gz
        gs-error-codes.patch)
sha256sums=('65256af389823bbc4ee4d25bfd1cc19023ffc29ae9f9677f2d200fa6e98bc7a8'
            '4be333af80378aba74c7bc3804727e3a3b49ccfaee0a8f9173094607e01b9b17')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

prepare() {
  cd ${_realname}-${pkgver}

  apply_patch_with_msg gs-error-codes.patch

  autoreconf -fi
}

build() {

  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  
  make DESTDIR=${pkgdir} install
}
